package com.sctvcloud.pingwu.ui.adapter.holder;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.load.engine.DiskCacheStrategy;

import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.pingwu.R;
import com.sctvcloud.pingwu.beans.CircleBean;
import com.sctvcloud.pingwu.ui.utils.GlideCircleTransform;
import com.sctvcloud.pingwu.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CommonCircleHolder extends BaseRecylerHolder<CircleBean> implements View.OnClickListener {
    @BindView(R.id.circle_title)
    protected CustomFontTextView title;
    @BindView(R.id.circle_img)
    protected ImageView circleImg;

    private CircleBean mNewsItem;

    public CommonCircleHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(CircleBean newsItem) {
        mNewsItem = newsItem;
        title.setText(TextUtils.isEmpty(newsItem.getName()) ? "" : newsItem.getName());
        String img = TextUtils.isEmpty(newsItem.getIamge())?newsItem.getImage():newsItem.getIamge();
        GlideUtil.getDynamicGlid(context, img, true).diskCacheStrategy(DiskCacheStrategy.NONE)
                .transform(new GlideCircleTransform(context)).into(circleImg);
    }

    @Override
    public void onClick(View v) {
        if (internalClick != null) {
            itemView.setTag(R.id.adapter_item_data_key, mNewsItem);
            internalClick.onItemInternalClick(itemView, v, getAdapterPosition());
        }
    }
}
